package org.jaronsource.sample.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import org.jaronsource.framework.core.dao.support.IGenericDao;
import org.jaronsource.framework.core.dao.support.Page;
import org.jaronsource.framework.core.dao.support.PageRequest;
import org.jaronsource.framework.core.dao.support.Criteria;
import org.jaronsource.framework.core.dao.support.Sort;
import org.jaronsource.framework.core.service.SearchForm;
import org.jaronsource.framework.core.service.SearchFormSupportGenericService;
import org.jaronsource.sample.dao.SysFuncDao;
import org.jaronsource.sample.domain.SysFunc;
import org.jaronsource.sample.service.SysFuncService;

@Service
public class SysFuncServiceImpl extends SearchFormSupportGenericService<SysFunc, Integer> implements SysFuncService {

	@Autowired
	private SysFuncDao sysFuncDao;

	@Override
	public IGenericDao<SysFunc, Integer> getDao() {
		return sysFuncDao;
	}

	@Override
	public Page<SysFunc> findPage( SearchForm searchForm ) {

		Criteria criteria = super.parseForm( searchForm );
		PageRequest pageRequest = searchForm.getPageRequest();
		Sort sort = new Sort().asc( "funcGroupCode" ).asc( "parent.funcId" ).asc( "funcOrder" );
		pageRequest.setSort( sort );

		return getDao().findPage( pageRequest, criteria );
	}

	@Override
	public List<SysFunc> findAll() {
		Sort sort = new Sort().asc( "funcGroupCode" ).asc( "parent.funcId" ).asc( "funcOrder" );
		return getDao().find( sort, new Criteria() );
	}

}